//计算days天后的日期(时间，天数)
function addDate(date,days){ 
	var d=new Date(date); 
	d.setDate(d.getDate()+days); 

	return d; 
}
Ext.onReady(function(){
	
	 var fromPanelInfo = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'房产信息',
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'房号',
			    	   name:'combinedName'
			    	   
				}, {
					 xtype:'displayfield',
			    	 fieldLabel:'房源状态',
			    	 name:'roomStatus'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'建筑面积',
			    	 name:'buildingArea'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'套内面积',
			    	 name:'innerArea'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'分摊面积',
			    	 name:'sharingArea'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'计价面积',
			    	 name:'buildingArea'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'拆前单价',
			    	 name:'unitPrice'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'拆前总价',
			    	 name:'totalPrice'
				} ]
			}]
		   
	   });
	 
	 
	 var sellInfo = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'datefield',
			    	   format:'Y-m-d',
			    	   fieldLabel:'开始有效日期',
			    	   id:'startValidity',
			    	   allowBlank:false,
			    	   blankText:'不能为空',
			    	   minValue:addDate(new Date(),0)
			    	   
				}, {
					 xtype:'datefield',
			    	 format:'Y-m-d',
			    	 fieldLabel:'结束有效日期',
			    	 id:'endValidity',
			    	 allowBlank:false,
			    	 blankText:'不能为空',
			    	 minValue:addDate(new Date(),0)
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					xtype : 'textarea',
					fieldLabel : '销控原因',
					width:500,
					id:'reason',
					allowBlank:false,
			    	blankText:'不能为空'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [{
					xtype : 'displayfield',
					fieldLabel : '经办人',
					value:userName
				}]
			}]
		   
	   });
	 
	  var fromPanel =  Ext.create('Ext.form.FormPanel',{
	       renderTo:Ext.getBody(),
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
		   	defaultType : 'textfield',
			defaults : {
				anchor : '100%'
			},
			fieldDefaults : {
				flex : 1
			},
	       items:[fromPanelInfo]
	       });
	  
	  Ext.create('Ext.Panel', {
			collapsible : false, 
			autoScroll : false, 
			defaultType : 'textfield',
			defaults : {
				anchor : '100%'
			},
			fieldDefaults : {
				flex : 1
			},
			title:'销控信息',
	        renderTo:Ext.getBody(),
	        items:[sellInfo],
	        dockedItems: [{
	            xtype: 'toolbar',
	            dock: 'bottom',
	            ui: 'footer',
	            layout: {
	                pack: 'center'
	            },
	            items: [{
	                minWidth: 80,
	                text: '保存',
	                id:'save_button',
	                handler:function(){
	                  	var form = sellInfo.getForm();
	                  	if(form.isValid()){
	                  		var parent={
		                			'roomId':roomId,
		                			'starttime':Ext.getCmp("startValidity").getValue(),
		                			'endTime':Ext.getCmp("endValidity").getValue(),
		                			'reason':Ext.getCmp("reason").getValue(),
		                			'controlType':0
		                	};
	                  	  	Ext.Ajax.request({
		                		url:jypath+'/marketing/sellControl/add',
		                		params:parent,
		                		callback: function (options, success, response) {
		                			 var obj = JSON.parse(response.responseText);
		                			 if(obj.res=="1"){
		                				 Ext.MessageBox.alert("系统提示", "提交成功! ", function(but) {  
		                					 var tabKey = "sell_"+roomId;
			        	                	 parent.TabControlRemove(tabKey);
	    				                 });  
		                				
		    						 }else{
		    							 Ext.MessageBox.alert("系统提示",obj.resMsg); 
		    						 }
		                		}
		                	});

	                  	}

	                }
	            },{
	                minWidth: 80,
	                text: '返回',
	                handler:function(){
	                	 var tabKey = "sell_"+roomId;
	                	 parent.TabControlRemove(tabKey);
	                }
	            }]
	        }
	        ]
			
	   });
	  
	  
	  
	  fromPanelInfo.getForm().load({
			url:jypath+'/marketing/sellControl/getprojectRoom',
			params:{'id':roomId},
			success:function(form, action){
				
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});
});